/*
 * Copyright (C) 2014 luke.
 * 
 * This file is part of Silvie.
 * 
 * Silvie is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Silvie is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Silvie.  If not, see <http://www.gnu.org/licenses/>.
 */

package silvie.resources.sprite;

import utils.PalettizedImage;

/**
 * AbstractSprite specialization for "simple" sprites. These sprites' data only
 * contain the pixel indices.
 * 
 * @author luke
 *
 */
public class SimpleSprite extends AbstractSprite {
	/**
	 * SimpleSprite constructor.
	 * 
	 * @see AbstractSprite#AbstractSprite(byte[], int, int, int)
	 */
	public SimpleSprite(byte[] spritePalette, int size, int width, int height) {
		super(spritePalette, size, width, height);
	}

	@Override
	public void decode() {
		int size = super.palettizedImage.getWidth() * super.palettizedImage.getHeight();
		short[] indices = new short[size];
		for (int i = 0; i < size; i++) {
			short indice = (short) (super.spriteData[i] & 0xFF);
			indices[i] = indice == SPR_TRANSPARENT_INDEX ? PalettizedImage.TRANSPARENT_INDEX : indice;
		}
		super.palettizedImage.setPixelIndices(indices);
	}
}
